package com.jiyun.service.impl;

import com.alibaba.csp.sentinel.util.StringUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiyun.login.pojo.finance.Reconciliation;
import com.jiyun.login.pojo.finance.ReconciliationVo;
import com.jiyun.mapper.ReconciliationMapper;
import com.jiyun.result.Result;
import com.jiyun.service.IReconciliationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2025-02-13
 */
@Service
public class ReconciliationServiceImpl extends ServiceImpl<ReconciliationMapper, Reconciliation> implements IReconciliationService {

    @Autowired
    private ReconciliationMapper reconciliationMapper;

    @Override
    public Result finAll(ReconciliationVo reconciliationVo) {
        Page<Reconciliation> reconciliations = new Page(reconciliationVo.getPages(), reconciliationVo.getSize());
        QueryWrapper<Reconciliation> queryWrapper = new QueryWrapper<>();
        if (!StringUtil.isEmpty(reconciliationVo.getCustomer())){
            queryWrapper.eq("customer",reconciliationVo.getCustomer());
        }
        if (!StringUtil.isEmpty(reconciliationVo.getSettlementStatus())){
            queryWrapper.eq("settlement_status",reconciliationVo.getSettlementStatus());
        }
        if (!StringUtil.isEmpty(reconciliationVo.getFormer())&&!StringUtil.isEmpty(reconciliationVo.getHoo())){
            queryWrapper.between("sign_time",reconciliationVo.getFormer(),reconciliationVo.getHoo());
        }
        Page<Reconciliation> reconciliationPage = reconciliationMapper.selectPage(reconciliations, queryWrapper);
        return Result.ok(reconciliationPage);
    }

    @Override
    public Result finApp(Integer id) {
        //详情
        Reconciliation reconciliation = reconciliationMapper.selectById(id);
        if (reconciliation!=null){
            return Result.ok(reconciliation);
        }
        return Result.fail();
    }
}
